<?php
namespace Store\Model;
use Think\Model;

class MemberCoreModel extends Model
{
    
    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
    );
    
    /**
     * @更新用户余额
     *
     * @param int $memberID            
     * @param int $memberMoney      
     * @param int $type inc + dec -       
     * @return array
     */
    public function setMemberMoney($memberID, $memberMoney, $type)
    {
        $data = array();
        if ($type == 'inc'){
            $data['member_money'] = array( 'exp', "member_money + {$memberMoney}" );
        } elseif($type == 'dec'){
            $data['member_money'] = array( 'exp', "member_money - {$memberMoney}" );
        }
        $data['update_time'] = time();
        return $this->where('member_id = ' . $memberID)->save($data);
    }
    
}
?>